package cloud.pangui.core.mongo.element;

import com.mongodb.MongoException;
import org.bson.Document;

/**
 * 值对象
 *
 * @Auther hepangui
 * @Date 2020/10/06 0001
*/
public class Value extends Ele {
	private Value() {
	}

	/**
	 * 值
	 */
	private Object object;

	/**
	 * 构建一个值对象
	 *
	 * @param o
	 * @return
	 */
	public static Value of(Object o) {
		Value value = new Value();
		value.object = o;
		return value;
	}

	@Override
	public Object toExpression() {
		return object;
	}

	@Override
	public Document build() {
		if (alias == null || "".equals(alias)) {
			throw new MongoException("值元素必须有别名");
		}
		return new Document(alias, object);
	}
}
